package com.guigu.www.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.www.pojo.*;
import com.guigu.www.service.DfileListService;
import com.guigu.www.service.FileService;
import jdk.nashorn.internal.ir.ReturnNode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class DfileListController {
    //制定设计单
    @Autowired
    DfileListService dfilelservice;


    //查询是否要制定产品
    @RequestMapping("queryfilegongxuzd.action")
    public PageVo<File> queryfilegongxuzd(File file,
                                        @RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
                                        @RequestParam(value = "pagesize", defaultValue = "5") int pagesize) {
        //条件查询
        QueryWrapper<File> queryWrapper = new QueryWrapper<File>();
            queryWrapper.eq("CHECK_TAG","S001-1");
            queryWrapper.eq("TYPE","Y001-1");
            queryWrapper.eq("DESIGN_PROCEDURE_TAG","G001-0");
        Page<File> page = dfilelservice.page(new Page<File>(pagenum, pagesize), queryWrapper);
        PageVo<File> pageVo = new PageVo<File>();
        pageVo.setRows(page.getRecords());
        pageVo.setTotal(page.getTotal());
        return pageVo;
    }

    //添加产品
    @RequestMapping("queryfilegongxuzd2.action")
    public PageVo<File> queryfilegongxuzd2(File file,
                                        @RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
                                        @RequestParam(value = "pagesize", defaultValue = "5") int pagesize) {
        //条件查询
        QueryWrapper<File> queryWrapper = new QueryWrapper<File>();
            queryWrapper.eq("CHECK_TAG","S001-1");
            queryWrapper.eq("TYPE","Y001-1");
        Page<File> page = dfilelservice.page(new Page<File>(pagenum, pagesize), queryWrapper);
        PageVo<File> pageVo = new PageVo<File>();
        pageVo.setRows(page.getRecords());
        pageVo.setTotal(page.getTotal());
        return pageVo;
    }



    //审核通过修改
    @RequestMapping("updatefilepojo.action")
    public Map updatemcppojo(@RequestBody File file
    ) {
        Map map = new HashMap();
        file.setDesignproceduretag("G001-1");
        boolean f = dfilelservice.updateById(file);
        if (f) {
            map.put("cm", "1");
        } else {
            map.put("cm", "0");
        }
        return map;
    }

    //不通过修改
    @RequestMapping("updatemcppojobiangeng.action")
    public Map updatemcppojobiangeng(@RequestBody File file
    ) {
        Map map = new HashMap();
        //未制定
        file.setDesignproceduretag("G001-0");
        boolean f = dfilelservice.updateById(file);
        if (f) {
            map.put("cm", "1");
        } else {
            map.put("cm", "0");
        }
        return map;
    }








    //根据产品查询设计单表
    @GetMapping("queryfilebyid.action/{id}")
    public File queryfilebyid(@PathVariable int id) {
        return dfilelservice.getById(id);
    }

    //根据产品查询设计单表
    @GetMapping("querybyfileid.action/{id}")
    public File querybyfileid(@PathVariable int id) {
        return dfilelservice.getById(id);
    }

    @RequestMapping("updatemcppojo2.action")
    public void updatemcppojo2(@RequestBody File file
    ) {
        UpdateWrapper<File> updateWrapper=new UpdateWrapper<File>();
        updateWrapper.set("DESIGN_PROCEDURE_TAG","G001-0").eq("PRODUCT_ID",file.getProductid());
        boolean f= dfilelservice.update(null,updateWrapper);
    }
}
